package com.gethistorics.components;

import java.io.File;
import java.io.FilenameFilter;
import java.util.Hashtable;

import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;

public class HistoricsIndex {   
   private File cacheFolder;
   private Hashtable invertedIndex = new Hashtable();
   private FilenameFilter JSONFileFilter = new FilenameFilter(){
      @Override
      public boolean accept(File dir, String name) {
         return new File(dir + File.separator + name).isFile() && name.toLowerCase().matches("\\.json$");
      }
   };
   
   public String getMessage(){
      return cacheFolder.getAbsolutePath();
   }
   
   public HistoricsIndex(String cfp){
      cacheFolder = new File(cfp);
   }
   
   public boolean buildIndex(){
      //get files ending in .json
      //add file to index
      if(!cacheFolder.exists() && !cacheFolder.isDirectory()) return false;
      
      File[] indexFiles = cacheFolder.listFiles(JSONFileFilter);
      for(int i=0; i<indexFiles.length; i++){
         System.out.println("found a file " + indexFiles[i].getName());
      }
      return true;
   }
   
   public void addFileToIndex(File f){
      
   }
}
